package com.dotflat.dict.controller;

import com.matt.commons.model.StatusResponse;
import com.matt.service.remoteCall.DTO.DictDataDTO;
import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.matt.foundation.constant.RequestConstant.TICKET;


/**
 * @author ：Ron
 * @date ：Created in 11/6/2020 5:07 PM
 */
@RestController
@RequestMapping("/v2/dict")
@Slf4j
@Api(tags = "字典 - ")
public class DictController {
    @Autowired
    SsoCallService ssoCallService;

    @ApiOperation(value = "增加一条记录")
    @PostMapping()
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "sort", value = "排序", required = false, dataType = "Long"),
            @ApiImplicitParam(paramType = "form", name = "label", value = "标签，显示名", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "value", value = "值", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "type", value = "类型", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "remark", value = "备注", required = false, dataType = "string"),

    })
    public StatusResponse add(@RequestHeader(TICKET) String ticket, Long sort, String label,String value, String type, String remark){

        DictDataDTO dict = new DictDataDTO();
        dict.setDictSort(sort);
        dict.setDictLabel(label);
        dict.setDictValue(value);
        dict.setDictType(type);
        dict.setRemark(remark);

        Integer ret = ssoCallService.addDictData(ticket, dict );

        return StatusResponse.success(ret);
    }

    @ApiOperation(value = "获取一个对象")
    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "label", value = "标签，显示名", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "form", name = "type", value = "类型", required = true, dataType = "string"),

    })
    public StatusResponse get(@RequestHeader(TICKET) String ticket, String label, String type){

        DictDataDTO dict = new DictDataDTO();
        dict.setDictLabel(label);
        dict.setDictType(type);
        List<DictDataDTO> ret = ssoCallService.getDictData(ticket, dict );

        return StatusResponse.success(ret);
    }

}
